package com.ttg.common.entities;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @author h
 * @version 1.0
 * @Description 分页需继承的类
 * @date 2023/07/05 14:52:11
 */
@Data
public class PageEntity implements Serializable {
    private static final long serialVersionUID = -8296480209706507160L;
    @ApiModelProperty("当前页数")
    private Integer page = 1;

    @ApiModelProperty("每页展示条数")
    private Integer pageSize = 10;

    public <T> BasePage<T> parse() {
        BasePage<T> page = new BasePage<>(getPage(), getPageSize());
        return page;
    }

    public Integer getPageSize() {
        if (pageSize > 1000) {
            pageSize = 1000;
        }else if(pageSize < 1){
            pageSize = 1;
        }
        return pageSize;
    }

    public Integer getPage() {
        if (page < 1) {
            page = 1;
        }
        return page;
    }
}
